package org.jeecg.modules.charge.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.ComUtil;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.entity.charge.ChargeInvoice;
import org.jeecg.modules.charge.service.impl.ChargeInvoiceServiceImpl;
import org.jeecg.vo.charge.ChargeInvoiceDepositExcel;
import org.jeecg.vo.charge.ChargeInvoiceExcel;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
* @Description: 日报表
* @Author: jeecg-boot
* @Date:   2019-08-08
* @Version: V1.0
*/
@Slf4j
@Api(tags="日报表")
@RestController
@RequestMapping("/b/charge/report")
public class ChargeReportController {

    @Autowired
    private ChargeInvoiceServiceImpl chargeInvoiceServiceImpl;

    /**
     * 日报表查询
     * @param
     * @return
     */
    @AutoLog(value = "日报表查询")
    @ApiOperation(value="日报表查询", notes="日报表查询")
    @PostMapping(value = "/generaTing")
    public Result<List<ChargeInvoice>> getChargeBillsAll(@RequestBody ChargeInvoice chargeInvoice) {
        Result<List<ChargeInvoice>> result = new Result<List<ChargeInvoice>>();
        try {
            List<ChargeInvoice>  invoices = chargeInvoiceServiceImpl.getInvoice(chargeInvoice);
            result.setSuccess(true);
            result.setResult(invoices);
        }catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return result;
    }

    /**
     * 导出excel
     *
     * @param chargeInvoice
     */
    @AutoLog(value = "日报表查询-导出")
    @ApiOperation(value="日报表查询-导出", notes="日报表查询-导出")
    @PostMapping(value = "/exportXls")
    public ModelAndView exportXls(@RequestBody ChargeInvoice chargeInvoice) {
        // Step.1 组装查询条件
        LoginUser user = SsoUtil.getLoginUser();
        List<ChargeInvoiceExcel>  invoices = chargeInvoiceServiceImpl.getInvoiceExcel(chargeInvoice);
        //List<ChargeInvoiceDepositExcel> list =  ComUtil.copy(invoices,ChargeInvoiceDepositExcel.class);
        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "收款日报导出数据");
        mv.addObject(NormalExcelConstants.CLASS, ChargeInvoiceExcel.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("收款日报导出数据", "导出人:" + user.getRealname(), "导出信息"));
        mv.addObject(NormalExcelConstants.DATA_LIST, invoices);
        return mv;
    }
}
